/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var ajaxRequest; // The variable that makes Ajax possible!
function ajaxFunction(url, cfunc){
    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }

    ajaxRequest.onreadystatechange = cfunc;
    ajaxRequest.open("GET", url, true);
    ajaxRequest.send();
}

var ajaxRequest2;  // The variable that makes Ajax possible!
function ajaxFunction2(url, cfunc){
    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequest2 = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequest2 = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest2 = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }

    ajaxRequest2.onreadystatechange = cfunc;
    ajaxRequest2.open("GET", url, true);
    ajaxRequest2.send();
}

var ajaxRequest3;  // The variable that makes Ajax possible!
function ajaxFunction3(url, cfunc){
    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequest3 = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequest3 = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest3 = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }

    ajaxRequest3.onreadystatechange = cfunc;
    ajaxRequest3.open("GET", url, true);
    ajaxRequest3.send();
}

function ajaxOnlineFriend(user) {
    ajaxFunction("OnlineFriend?Username=" + user, function()
    {
        // Create a function that will receive data sent from the server
        if(ajaxRequest.readyState == 4){
            user_view = user;
            document.getElementById("listfriends").innerHTML=ajaxRequest.responseText;
            setTimeout("ajaxOnlineFriend('"+ user_view + "')",10000);
        }
    });
}

function ajaxOfflineFriend(user) {
    ajaxFunction3("Friends?Username=" + user, function()
    {
        // Create a function that will receive data sent from the server
        if(ajaxRequest3.readyState == 4){
            user_view = user;
            document.getElementById("offlistfriends").innerHTML=ajaxRequest3.responseText;
            setTimeout("ajaxOfflineFriend('"+ user_view + "')",10000);
        }
    });
}

function ajaxCategory() {
    ajaxFunction2("Category", function()
    {
        // Create a function that will receive data sent from the server
        if(ajaxRequest2.readyState == 4){
            document.getElementById("isiRoom").innerHTML=ajaxRequest2.responseText;
        }
        setTimeout("ajaxCategory()", 10000);
    });
}


var ajaxRequestlistRoomDibuka;  // The variable that makes Ajax possible!
function ajaxFunctionlistRoomDibuka(url, cfunc){
    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequestlistRoomDibuka = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequestlistRoomDibuka = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequestlistRoomDibuka = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }

    ajaxRequestlistRoomDibuka.onreadystatechange = cfunc;
    ajaxRequestlistRoomDibuka.open("GET", url, true);
    ajaxRequestlistRoomDibuka.send();
}

//list room yang sedang dibuka
function listRoomDibuka(username)
{
    ajaxFunctionlistRoomDibuka("ChatProcess?Action=listRoomDibuka&username=" + username , function()
    {
        // Create a function that will receive data sent from the server
        if(ajaxRequestlistRoomDibuka.readyState == 4){
            document.getElementById('roomdibuka').innerHTML = ajaxRequestlistRoomDibuka.responseText;
            setTimeout("listRoomDibuka('"+ username + "')",10000);
        }
    });
}

var ajaxRequestchataktif;  // The variable that makes Ajax possible!
function ajaxFunctionchataktif(url, cfunc){
    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequestchataktif = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequestchataktif = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequestchataktif = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }

    ajaxRequestchataktif.onreadystatechange = cfunc;
    ajaxRequestchataktif.open("GET", url, true);
    ajaxRequestchataktif.send();
}

//list room yang sedang dibuka
function chatdibuka(username)
{
    ajaxFunctionchataktif("ChatProcess?Action=showRoom&Room=" + getroomdibukasaatini()+"&username=" + username , function()
    {
        // Create a function that will receive data sent from the server
        if(ajaxRequestchataktif.readyState == 4){
            document.getElementById('isiChatting').innerHTML = ajaxRequestchataktif.responseText;
            setTimeout("chatdibuka('"+ username + "')",10000);
        }
    });
}

var ajaxShowRoomUser;  // The variable that makes Ajax possible!
function ajaxFunctionShowRoomUser(url, cfunc){
    try{
        // Opera 8.0+, Firefox, Safari
        ajaxShowRoomUser = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxShowRoomUser = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxShowRoomUser = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }

    ajaxShowRoomUser.onreadystatechange = cfunc;
    ajaxShowRoomUser.open("GET", url, true);
    ajaxShowRoomUser.send();
}

//list room yang sedang dibuka
function showRoomUser()
{
    ajaxFunctionShowRoomUser("ChatProcess?Action=ajaxshowRoomUser&Room=" + getroomdibukasaatini() , function()
    {
        // Create a function that will receive data sent from the server
        if(ajaxShowRoomUser.readyState == 4){
            document.getElementById("chatlist").innerHTML=ajaxShowRoomUser.responseText;
            setTimeout("showRoomUser()",10000);
        }
    });
}

//var ajaxbot;  // The variable that makes Ajax possible!
//function ajaxFunctionbot(url, cfunc){
//    try{
//        // Opera 8.0+, Firefox, Safari
//        ajaxbot = new XMLHttpRequest();
//    } catch (e){
//        // Internet Explorer Browsers
//        try{
//            ajaxbot = new ActiveXObject("Msxml2.XMLHTTP");
//        } catch (e) {
//            try{
//                ajaxbot = new ActiveXObject("Microsoft.XMLHTTP");
//            } catch (e){
//                // Something went wrong
//                alert("Your browser broke!");
//                return false;
//            }
//        }
//    }
//
//    ajaxbot.onreadystatechange = cfunc;
//    ajaxbot.open("GET", url, true);
//    ajaxbot.send();
//}
//
////list room yang sedang dibuka
//function botaktif()
//{
//    ajaxFunctionbot("ChatProcess?Action=ajaxshowRoomUser&Room=" + getroomdibukasaatini() , function()
//    {
//        // Create a function that will receive data sent from the server
//        if(ajaxbot.readyState == 4){
//            document.getElementById("chatlist").innerHTML=ajaxbot.responseText;
//        }
//    });
//}



